package com.zzl.car.util;

import java.sql.Timestamp;
import java.time.LocalDate;
import java.util.Calendar;
import java.util.Date;

public class ZtimeUtil {
    // 计算时间差
    public static double getTimeSubHours(Timestamp startTime,Timestamp endTime){
        long stime = startTime.getTime();
        long etime = endTime.getTime();
        // 算差了几个小时 60*60*1000
        double result =(double) ((etime-stime)/(60*60*1000)*1.0);
        System.out.println(result);
        return Math.abs(result);
    }
    public static double getTimeSubHours(long startTime,long endTime){
        // 算差了几个小时 60*60*1000
        double result =(double) ((startTime-endTime)/(60*60*1000)*1.0);
        System.out.println(result);
        return Math.abs(result);
    }
    // 计算天数 ，四舍五入
    public static double getTimeSubDayNoExactly(Timestamp startTime,Timestamp endTime){
        double hours = getTimeSubHours(startTime,endTime);
        double day = hours/24;
        double resultDay = (int)day;
        if(resultDay == day)
            return resultDay;
        else if( (resultDay+0.5)>=day)
            return resultDay+0.5;
        else
            return resultDay+1;
    }
    public static double getTimeSubDayNoExactly(long startTime,long endTime){
        double hours = getTimeSubHours(startTime,endTime);
        double day = hours/24;
        double resultDay = (int)day;
        if(resultDay == day)
            return resultDay;
        else if( (resultDay+0.5)>=day)
            return resultDay+0.5;
        else
            return resultDay+1;
    }
}
